﻿using System;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using HigLabo.Net.Extensions;
using System.Collections;

namespace HigLabo.Net.Twitter
{
    /// <summary>
    /// 
    /// </summary>
    public class ErrorCollection : Collection<Error>
    {
        /// <summary>
        /// 
        /// </summary>
        public ErrorCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            if (!System.Text.RegularExpressions.Regex.IsMatch(jsonText, "\"(code|message)\":.*"))
            {
                this.Add(new Error(0, jsonText));
                return;
            }
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;

            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Error(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class UserMentionCollection : Collection<UserMention>
    {
        /// <summary>
        /// 
        /// </summary>
        public UserMentionCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new UserMention(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class RateLimitInfoCollection : Collection<RateLimitInfo>
    {
        /// <summary>
        /// 
        /// </summary>
        public RateLimitInfoCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new RateLimitInfo(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class LanguageCollection : Collection<Language>
    {
        /// <summary>
        /// 
        /// </summary>
        public LanguageCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Language(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class LocationCollection : Collection<Location>
    {
        /// <summary>
        /// 
        /// </summary>
        public LocationCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Location(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class TrendCollection : Collection<Trend>
    {
        /// <summary>
        /// 
        /// </summary>
        public TrendCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Trend(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class TrendsCollection : Collection<Trends>
    {
        /// <summary>
        /// 
        /// </summary>
        public TrendsCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Trends(i.ToString()));
                }
            }
        }
    }
    
    /// <summary>
    /// 
    /// </summary>
    public class TrendLocationCollection : Collection<TrendLocation>
    {
        /// <summary>
        /// 
        /// </summary>
        public TrendLocationCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new TrendLocation(i.ToString()));
                }
            }
        }
    }
    
    /// <summary>
    /// 
    /// </summary>
    public class CoordinateCollection : Collection<Coordinate>
    {
        /// <summary>
        /// 
        /// </summary>
        public CoordinateCollection()
        {
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class PlaceCollection : Collection<Place>
    {
        /// <summary>
        /// 
        /// </summary>
        public PlaceCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Place(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class StatusCollection : Collection<Status>
    {
        /// <summary>
        /// 
        /// </summary>
        public StatusCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Status(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class HashTagCollection : Collection<HashTag>
    {
        /// <summary>
        /// 
        /// </summary>
        public HashTagCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new HashTag(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class UserCollection : Collection<User>
    {
        /// <summary>
        /// 
        /// </summary>
        public UserCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new User(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SuggestionCollection : Collection<Suggestion>
    {
        /// <summary>
        /// 
        /// </summary>
        public SuggestionCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Suggestion(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class DirectMessageCollection : Collection<DirectMessage>
    {
        /// <summary>
        /// 
        /// </summary>
        public DirectMessageCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new DirectMessage(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class FriendshipCollection : Collection<Friendship>
    {
        /// <summary>
        /// 
        /// </summary>
        public FriendshipCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Friendship(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SavedSearchCollection : Collection<SavedSearch>
    {
        /// <summary>
        /// 
        /// </summary>
        public SavedSearchCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new SavedSearch(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class ListCollection : Collection<List>
    {
        /// <summary>
        /// 
        /// </summary>
        public ListCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new List(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class UrlCollection : Collection<Url>
    {
        /// <summary>
        /// 
        /// </summary>
        public UrlCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Url(i.ToString()));
                }
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class MediaCollection : Collection<Media>
    {
        /// <summary>
        /// 
        /// </summary>
        public MediaCollection(String jsonText)
        {
            SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public void SetProperty(String jsonText)
        {
            var cc = JsonConvert.DeserializeObject(jsonText) as JContainer;
            if (cc != null)
            {
                foreach (var i in cc)
                {
                    this.Add(new Media(i.ToString()));
                }
            }
        }
    }
}
